<template>
  <!-- 班级列表 -->
  <div class="section-content" id="classesList">
    <h2>班级信息</h2>
    <div class="content">
      <div class="content-info">
        <h3>班级数据</h3>
        <div>
          <table border="1">
            <thead>
              <tr>
                <th>班级编号</th>
                <th>班级名称</th>
                <th>班主任</th>
                <th>操作</th>
              </tr>
            </thead>
            <tbody id="classesTb">
              <tr v-for="item in classesdata" :key="item._id">
                <td>{{ item._id }}</td>
                <td>{{ item.name }}</td>
                <td>班主任</td>
                <td>
                  <a href="#">修改</a>
                  <a href="#" @click.prevent="delclass(item._id)">删除</a>
                </td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import api from "../http/api";
export default {
  data() {
    return {
      pages: 0,
      total: 0,
      classesdata: [],
      currentPage: 1,
      pageSize: 20,
      //   soso: { type: "name", value: "" },
    };
  },
  mounted() {
    this.getclasses();
  },
  methods: {
    async getclasses() {
      //发送请求获取学生数据
      const data = await api.classes.getclasses({
        pageSize: this.pageSize, //每页显示条数
        currentPage: this.currentPage, //当前也
      });
      if (data.code) {
        // console.log(data.data);
        this.pages = data.data.pages;
        this.total = data.data.total;
        this.classesdata = data.data.result;
        // this.currentPage = data.data.data.currentPage;
      }
      //   console.log(data.data.data.result);
    },
    async delclass(_id) {
      const data = await api.classes.delclass(_id);
      console.log(data);
      if (data.code) {
        this.getclasses();
      }
    },
  },
};
</script>

<style>
</style>